home *** CD-ROM | disk | FTP | other *** search
- unit glLight;
-
- interface
- Uses windows,Classes,opengl, GLFuncs, GLWin;
-
- Type
- TCustomGLLightWindow = class(TCustomOpenGLWindow)
- // has all the lighting stuff
- private
- (* procedure PaintWindow(DC: HDC); override;*)
-
- protected
- //Structures for lighting
- fLightingState,
- // turns lighting on/off
- fLocalViewer,
- // turn on/off local viewer lighting calcs WARNING can be slow
- fTwoSided : Boolean;
- //turn on/off two sided lighting WARNING can be slow
- fGlobalAmbient : tGLLightVal;
- // background or global lighting value
- fHeadLightState : Boolean;
- //light0 is a headlight and tracks the viewer position
- // the current viewer will have a pointer to the headlight assigned
-
- //Set up the global lighting values
-
- fLights : Array[0..7] of tGLLight;
-
- procedure DestroyWindowHandle; Override;
- // get rid of the light stuff
- Procedure GLSessionSetUp; Override;
- {Set up when GL session is started}
-
- Procedure SetheadLightOn(Value:Boolean);
- //turn on and off the headlight
- Procedure SetLightingState(Value:Boolean);
- //turn omn lighting and set global values
- Procedure BuilsLightSetUpList;
- Procedure SetGlobalAmbient(aVal: tGLLightVal);
-
- Public
- constructor Create(AOwner: TComponent); Override;
- destructor Destroy; override;
-
- Procedure BuildDisplayLists; Override;
- {This procedure builds all the standard display objects for the gl
- session}
- Procedure LightOn(aLightNum:SmallInt);
- //turn designated light on
- Procedure LightOff(aLightNum:SmallInt);
- //turn designated light off
- Function IsLightOn(aVal:SmallInt):Boolean;
- //reuturn true if the specified light is on
- Property HeadLightOn:Boolean Read fHeadLightState Write SetHeadLightOn;
- Property LightingOn:Boolean Read fLightingState Write SetLightingState;
- Property Ambient:tGLLightVal Read fGlobalAmbient write fGlobalAmbient;
- end;
-
- {procedure Register;}
- (*************************************************************)
- (*************************************************************)
- implementation
- (*************************************************************)
- constructor TCustomGLLightWindow.Create(AOwner: TComponent);
- Var I:LongInt;
- Begin
- Inherited Create(aOwner);
- With fGlobalAmbient do
- Begin
- R:=0.0;G:=0.0;B:=0.0;A:=1.0//Default values
- end;
- fLightingState:=False;
- // turns lighting on/off
- fLocalViewer :=False;
- // turn on/off local viewer lighting calcs WARNING can be slow
- fTwoSided :=False;
-
- For I:=0 to 7 do fLights[I]:=tGLLight.Create($4000+i);
- // set up the light values
- fViewer.Headlight:=fLights[0];
-
- end;
- (*************************************************************)
- Destructor TCustomGLLightWindow.Destroy;
- Var I:Smallint;
- Begin
- For I:=0 to 7 do fLights[I].Free;
- Inherited;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.SetGlobalAmbient(aVal: tGLLightVal);
- Begin
- If (fGlobalAmbient.R=aVal.R) and
- (fGlobalAmbient.G=aVal.G) and
- (fGlobalAmbient.B=aVal.B) and
- (fGlobalAmbient.A=aVal.A) then exit;
- fGlobalAmbient:=aVal;
- BuilsLightSetUpList;
- If fLightingState then glCallList(fGeneralLists+dlLightsOn);
- end;
- (*************************************************************)
- procedure TCustomGLLightWindow.DestroyWindowHandle;
- Begin
- Inherited DestroyWindowHandle;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.GLSessionSetUp;
- {Set up when GL session is started}
- Begin
- Inherited GLSessionSetUp;
- If fHRC=0 then exit;
- If fLightingState then glCalllist(fGeneralLists+ dlLightsOn);
- end;
-
- Procedure TCustomGLLightWindow.BuilsLightSetUpList;
- Begin
- glNewList(fGeneralLists+dlLightsOn,GL_COMPILE);
- glEnable(GL_Lighting);
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT,@fGlobalAmbient);
- If fLocalViewer then
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1) else
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,0);
- If fTwoSided then
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1) else
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
- glEnable(GL_COLOR_MATERIAL);
- glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
- glEndList;
- end;
- (******* ******************************************************)
- Procedure TCustomGLLightWindow.BuildDisplayLists;
- Begin
- If assigned(fShareGL) or not fStdDisplayList then exit;
- Inherited ;
- iF FGENERALlISTS=0 then exit;
- // light model ON
- BuilsLightSetUpList;
-
- // Light model OFF
- glNewList(fGeneralLists+dlLightsOff,GL_COMPILE);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,0);
- glDisable(GL_COLOR_MATERIAL);
- glDisable(GL_Lighting);
- glEndList;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.SetheadLightOn(Value:Boolean);
- //turn on and off the headlight
- Begin
- If fHeadLightState=Value then exit;
- fHeadLightState:=Value;
- EnableGL;
- If fHeadLightState then LightOn(0) else LightOff(0);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.SetLightingState(Value:Boolean);
- //turn omn lighting and set global values
- Begin
- If fLightingState=Value then exit;
- fLightingState:=Value;
- EnableGL;
- If not fLightingState and fHeadLightState then SetHeadLightOn(False);
- If fLightingState then
- glCallList(fGeneralLists+dlLightsOn) else
- glCallList(fGeneralLists+dlLightsOff);
- Repaint;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.LightOn(aLightNum:SmallInt);
- Begin
- If (aLightNum>7)or (aLightNum<0) then exit;
- If not fLightingState then SetLightingState(True);
- fLights[aLightNum].TurnLightOn;
- end;
- (*************************************************************)
- Procedure TCustomGLLightWindow.LightOff(aLightNum:SmallInt);
- Begin
- If (aLightNum>7)or (aLightNum<0) then exit;
- fLights[aLightNum].TurnLightOff;
- end;
- (*************************************************************)
- Function TCustomGLLightWindow.IsLightOn(aVal:SmallInt):Boolean;
- //reuturn true if the specified light is on
- Begin
- Result:=False;
- If (aVal>7)or (aVal<0) then exit;
- Result:=fLights[aVal].IsOn;
- end;
- (*************************************************************)
- (*************************************************************)
- (*procedure Register;
- begin
- RegisterComponents('OpenGL', [TCustomGLLightWindow]);
- end;
- *)
- end.
-